package cn.wolfcode.mq;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;

/**
 * MQ 监听异步发送消息的回调函数
 */
@Slf4j
public class DefaultMessageSendCallback implements SendCallback {

    private String tag;
    public DefaultMessageSendCallback(String tag){
        this.tag = tag;
    }

    @Override
    public void onSuccess(SendResult sendResult) {
        log.info("[{}] 消息发送成功 msgId:{}",tag,sendResult.getMsgId());
    }

    @Override
    public void onException(Throwable throwable) {
        log.warn("[{}] 消息发送失败:{}",tag,throwable.getMessage());
    }
}
